// pages/home/home-nav/medical-condition/bpm-control/bpm-chart1/bpm-chart1.ts
// @ts-ignore
import * as echarts from '../../../../../../components/ec-canvas/echarts';
import { initEcharts } from '../../../../../../utils/util';

var option = {
  grid: {
    x: 35, // 左
    y: 20, // 上
    x2: 10, // 右
    y2: 30, // 下
  },
  tooltip: {},
  xAxis: {
    data: [],
  },
  yAxis: {},
  series: [{
    type: 'bar',
    data: [],
  }],
};

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    ec: {
      lazyLoad: true, // 延迟加载
    },
    heartratetype: {
      categories: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'],
      data: [100, 140, 230, 100, 130, 140, 230],
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {
    changeChart() {
      // 更新数据重新数据初始化
      const canvasComponent = this.selectComponent("#bpm-chart1");
      // note: 动态获取数据后更新this.data.heartratetype，即可。
      const heartRateData = {
        categories: this.data.heartratetype.categories,
        data: this.data.heartratetype.data,
      };
      const options = this.changeOptionsData(heartRateData);
      initEcharts(options, canvasComponent);
    },
    // 传入动态数据
    changeOptionsData(initData: any) {
      option.xAxis.data = initData.categories;
      option.series[0].data = initData.data;
      return option;
    }
  },
  /*
  * 组件所在页面的生命周期
  */
  pageLifetimes: {
    show: function () {
      this.changeChart();
    },
  },
  /*
  * 组件自己的生命周期
  */
  lifetimes: {
    attached: function () {
      this.changeChart();
    }
  }
});
